function sad = sadfun(paramtrans,paramlow,paramup,weights,targetdata,mw,mw16,p)

% detransform parameters
param = (1-paramtrans).*paramlow + paramtrans.*paramup;

% compute model targets
t = targetfun(param,mw,mw16,p);

% compute deviations from data moments
dev = t.targets(1:size(targetdata))-targetdata;

% compute weighted sum of absolute deviations
sad = sum(abs(dev.*weights));

end